#if 0
// Virtual memory management
// handle page faults

#include <page.h>
#include <vmm.h>
#include <panic.h>
#include <macro.h>

// 16, 32, 64, 128, 256, 512
// 1024, 2048, 4096

// address where we can map a page and carve it up

#define PROCESS_PAGE_STACK	(0xf0000000 + (2*PAGE_SIZE))
#define PROCESS_PAGE_DIRS	0xf4000000
#define STAGING_AREA 		0xf8000000

page_t *process_page_stack, *process_page_stack_head;
unsigned int kernel_heap_pages, process_pages = 0, process_pages_4m = 0;
unsigned int process_page_dirs = 0, process_page_alloc = 0;

unsigned int enlarge_heap(unsigned int num_pages) {
  unsigned int i;
  page_t new;
  for (i = 1; i<= num_pages; i++) {
    new = pop_page();
    map_page(new, HEAP_BASE + (PAGE_SIZE * kernel_heap_pages));
    kernel_heap_pages++;
  }
  return i;
}

void push_process_page(page_t *base) {
  *process_page_stack = *base;
  process_page_stack++;
  process_pages++;
}

page_t *pop_process_page() {
  page_t *ret = process_page_stack;
  if (*ret == 0) panic("process pages exhausted");
  process_page_stack--;
  process_pages--;
  return ret;
}

void setup_process_page_stack() {
 page_t *newpage = pop_page();
 map_page(newpage, PROCESS_PAGE_STACK);
 process_page_stack_head = process_page_stack = (page_t*)PROCESS_PAGE_STACK;
 memset(process_page_stack, 0, sizeof(page_t);
}

void map_process_page(page_t phys, page_t virt) {
 proces_page_alloc++;
// if ((process_page_dirs * 1024) < process_page_alloc)

 if(kern_pd[mask_4m(virt)] & PAGE_PRESENT) {
   panic("don't want to map an application page over another page");
 }

// pd_set(

}
void unmap_process_page(page_t virt) {

}

void enlarge_process_page_pool() {
  unsigned int i;
  page_t newpage = pop_page();
  
  for (i = 0; i <= 1023; i++) {
    // carve into 4k chunks
    push_process_page(newpage + (4096 * i));
  }  
}



void build_kernel_heap() {
  enlarge_heap(min(max(page_depth / 4, 4), 2));
  printf("initial kernel heap at %08x, %d pages", HEAP_BASE, kernel_heap_pages);    
}



//// XXXXXXX
/// this whole source file is a heap of shit, when i end up writing malloc etc i'll set it up
void *kmalloc() {
 
}

void kfree(void * what) {

}

#endif // seriosuly
